package com.sx.pipeline.ui.supply.viewinquiry

import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.lxj.xpopup.XPopup
import com.sx.pipeline.BR
import com.sx.pipeline.R
import com.sx.pipeline.adapter.ViewInquiryAdapter
import com.sx.pipeline.app.base.CYDataBindingBaseActivity
import com.sx.pipeline.app.config.IntentKey
import com.sx.pipeline.arouth.RouteManager
import com.sx.pipeline.arouth.RoutePath
import com.sx.pipeline.databinding.ActViewInquiryBinding
import com.sx.pipeline.databinding.ActViewQuoteListBinding
import com.sx.pipeline.repos.http.res.ReleaseSupplyVo
import com.sx.pipeline.repos.http.res.ViewInquiryVo
import com.sx.pipeline.ui.supply.ReleaseSupplyVM
import com.sx.pipeline.ui.supply.frag.ReleaseSupplyListAdapter


/**
 * @Author: YY
 * @Date: 2022/4/5
 * @Description: 查看询价
 */
@Route(path = RoutePath.Mine.VIEW_INQUIRY_LIST)
class ViewInquiryActivity : CYDataBindingBaseActivity<ActViewInquiryBinding, ReleaseSupplyVM>(R.layout.act_view_inquiry),View.OnClickListener  {
    private lateinit var mAdapter:ViewInquiryAdapter
    @JvmField
    @Autowired(name = IntentKey.ID)
    var orderId: Int? = 0

    override fun initData() {
        super.initData()
        mBinding.setVariable(BR.onClick, this)
        mBinding.titleBar.leftView.setOnClickListener {
            finish()
        }
        //请求询价列表
        orderId?.let { mViewModel.getInquiryList(it) }
    }

    override fun initListener() {
        super.initListener()
        mBinding.recyclerView.layoutManager = LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false)
        mAdapter = ViewInquiryAdapter()
        mBinding.recyclerView.adapter = mAdapter

        mBinding.refreshLayout.setOnRefreshListener {
            //请求询价列表
            orderId?.let { mViewModel.getInquiryList(it) }
            mBinding.refreshLayout.finishRefresh()
        }
    }


    private fun initRv() {
        if (!this::mAdapter.isInitialized) {
            mAdapter = ViewInquiryAdapter()
            mBinding.recyclerView.layoutManager =
                LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
        }
        mAdapter.setOnItemClickListener { adapter, view, position ->

        }
        mBinding.recyclerView.adapter = mAdapter
    }


    override fun initViewObservable() {
        super.initViewObservable()
        observe(mViewModel.viewInquiryListEvent){
            initRv()
            val inquiryList = it as List<ViewInquiryVo>
            mAdapter.data= inquiryList as MutableList<ViewInquiryVo>
        }
    }

    override fun onClick(v: View?) {
        when (v?.id) {

        }
    }

}